<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>材料申请审批供货</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css">
    <style>
        .details ul li {width: 50%;float: left;}
        .layui-table thead th{text-align: left;}
        .layui-table td{text-indent: 1rem; font-size: 12px; color: #333;}
        .detailed{background-color: #FFF; font-size: 12px; color: #333333; line-height: 24px;margin-top: 8px;}
        /*.details ul,li{list-style: inherit;}*/
        .details{margin-top: 10px;}
        .detailed p:after {
            content: "\0020";
            display: block;
            height: 0;
            clear: both;
        }
        .detailed p:before {content: "● "; color: #e3e3e3; font-size: 12px; margin-right: 5px; float: left;}
        .detailed .detaL{width: 120px;display: inline-block; float: left;    padding-right: 20px;}
        .detailed .dataR{display: inline-block;float: left;}
        .detailed p{margin-bottom: 10px;}

        .detailedfoot ul {display: flex;justify-content: space-around;}
        .layui-table thead th{text-align: left;padding: 10px;}

        .layui-table td{text-indent: 1rem; font-size: 12px; color: #333;}
        table tbody tr td{text-align: left;}
        .maskmain table td, th{text-align: left;}
        .detailedfoot{padding: 15px 35px;height:50%;overflow: auto;}
        .engineering{width:100%;display: inline-block;float: left; padding: 0 10px;margin-left: -10px;margin-bottom: 20px;}
        /*.details{height: 30px; font-size: 16px;line-height: 30px;}*/
        /*.details ul{display: flex;justify-content: space-between;}*/
        .titles{height: 40px;line-height: 40px;font-size: 20px;}
        .detailedfoot table tbody tr{height: 40px;border-bottom: 1px solid #e3e3e3;}
        .detailwarp{padding-left:22px;}
        .shenheliang input{width: 100px;border-radius: 5px;}
        .layui-form-select{margin: 0;}
        .tijiao{float: right;}
        .cailiao,.zhuantai{width: 130px; padding-right: 10px;}
        .detailedfoot{height: 58vh;}

        .MOVE_mainL,.MOVE_mainR{display: inline-block;}
        .MOVE_mainL{text-align: center;width: 30%;}
        .MOVE_mainR{text-align: left;width: 70%;}
        #MOVE_main{text-align: center;}
        #MOVE_main p{line-height: 30px;}
        .MOVE_table{width: 100%; overflow-x: auto;}
        .MOVE_table table{width: 240%!important; text-align: center;}
        .MOVE_table table thead tr{background-color: #F5F5F5; height: 40px;font-size: 15px;}
        .MOVE_table thead tr th{text-align: center;}
        .MOVE_table tbody tr td{text-align: left; height: 30px;line-height: 30px;}
        .MOVE_foot{height: 50px;background-color: #253147;position: absolute;bottom: 0;width: 100%;text-align: right;}
        .close{background-color: #253147;top:-16px;}
        .layui-table td, .layui-table th{padding:0}
        @media screen and (max-width: 750px) {
            .MOVE_table{height: 60vh;}
            .xuanze {width: 80px;}
            .beizu,._num{width: 80px;}
            .layui-table thead tr th{text-align: left;text-indent: 1em;}
            .layui-table tbody tr td{text-align: left;text-indent: 1em;}
            .checkboxs{text-indent: 0!important;}
            .tijiaos{position: absolute;top: 0;right: 0; background-color: transparent;border: 0;font-size: 20px;
                height: 45px; line-height: 45px;margin-right: 15px!important;color: #FFF;}
            .layui-table thead th{text-align: left;padding: 0px;}
        }
        .detailedfoot{padding: 0;}
        /*.detailedfoot table{width: 140%!important;}*/
        .detailedfoot{margin-top: 20px;}
        .layui-anim{height: 150px; z-index: 9999;}
    </style>
</head>
<body>
<div class="_PC">
    <form class="layui-form layui-form-pane" action="" >
        <button class="layui-btn" type="button" onclick="history.back(-1);" style="margin-left: 24px;"><i class="layui-icon">
        </i></button>
        <button class="layui-btn tijiao" type="button" style="float: right;">提交</button>
        <div class="detailwarp">

        </div>

        <!--<select name="" id="">-->
        <!--<option value="">请选择</option>-->
        <!--</select>-->

    </form>
</div>
<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/base64.js"></script>

<script src="../../../resources/js/api.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate','laytpl'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laytpl=layui.laytpl
            ,laydate = layui.laydate;
        var materials1= new Object;       //创建新的对象接受值
        var materials2= new Object;       //创建新的对象接受值
        var materials3= new Object;       //创建新的对象接受值
        var materials4= new Object;       //创建新的对象接受值

        //监听全选
        form.on('checkbox(allChoose)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');         //找到tbody下的所有多选框
            child.each(function(index, item){                             //循环每个参数item  每个多选框
                item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
//                $(item).trigger('click');
            });
            form.render('checkbox');                                      //局部刷新多选框  保持页面操作一致性
        });
        //监听单个点击多选
        form.on('checkbox(filter)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var _this=data.othis;
            var chuandi=new Object();
            chuandi.jia=$(_this).parents('tr').attr('idang');
            chuandi.id=$(_this).parents('tr').attr('id');
            chuandi.mat_id=$(_this).parents('tr').attr('mat_id');
            chuandi.names=_this.parents('th').next().text();
            chuandi.guige=_this.parents('th').next().next().text();
            chuandi.num=_this.parents('th').next().next().next().text();
            //console.log(chuandi)
            $('.tijiao').removeClass('layui-btn-disabled');



//            //console.log($(data.elem).parent(), 'is i======================== parent =')

            if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                $('.beixuan table tbody').append('<tr id="'+chuandi.id+'" mat_id="'+chuandi.mat_id+'" idang="'+chuandi.jia+'">\n' +
                    '                                    <th class="names">'+chuandi.names+'</th>\n' +
                    '                                    <th class="guige">'+chuandi.guige+'</th>\n' +
                    '                                    <th class="nums">\n' +
                    '                                        <input type="number" class="inputs" lay-verify="required" value="'+chuandi.num+'"/>\n' +
                    '                                        <input type="hidden" class="numson" lay-verify="required" value="'+chuandi.num+'"/>\n' +
                    '                                    </th>\n' +
                    '                                </tr>')
            }else{                          //否则循环下半部所有的tr删除对应的tr
                $('.beixuan table tbody tr').each(function () {
                    if($(this).attr('id')==chuandi.id){
                        $(this).remove();
                    }

                })
            }



        });
        var datas = {};   //新建一个对象  用以数据去重
            ajaxs('/api/matperson/gcMatFeedSel.do','post',{'type':sessionStorage.type,'remark': sessionStorage.MOVE_ID,'p':getCookie('yanzheng')},function (data) {
                var gongchenggaikuo = '';
                //console.log(data,'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
                var datas=data.data;
                var materials1,materials2,materials3,materials4=new Object();
                materials1=data.fullDown.fullDown1;
                materials2=data.fullDown.fullDown2;
                materials3=data.fullDown.fullDown3;
                materials4=data.fullDown.fullDown4;

                for (var i=0;i<datas.length;i++) {                      //循环获取对象的某一个
                    if(i==0){
                        $('.detailwarp').append('<div class="engineering">' +           //添加共有部分
                            '    <div class="titles" names="11">11</div>' +
                            '    </div>'); 
                    }
                    
                        if (i == 0) {                                               //判断是否是第一次渲染
                            $("[names='11']").after('<div class="details">\n' +
                                '        <ul>\n' +
                                '            <li><span class=\'detaL\'>申请单单号：</span><span class="dataR">' + datas[i].feed_Code+ '</span></li>' +
                                '            <li><span class=\'detaL\'>项目名称：</span><span class="dataR">' + datas[i].eppName + '(12312' + datas[i].eppStaEnd +')'+ '</span></li>' +
                                '            <li><span class=\'detaL\'>施工单位：</span><span class="dataR">' + datas[i].compName1 + '</span></li>' +
                                '            <li><span class=\'detaL\'>供货时间：</span><span class="dataR">' + datas[i].supply_Time + '</span></li>\n' +
                                '            <li><span class=\'detaL\'>收货地址：</span><span class="dataR">' + sessionStorage.f_adrs + '</span></li>\n' +
                                '        </ul>\n' +
                                '    </div>' +
                                ' <div class="detailed">\n' +
                                '    </div>' +
                                ' <div class="detailedfoot">' +
                                '<table class="layui-table table">\n' +
                                '           <thead class="detailedfoot_thea">\n' +
                                '               <th>材料名称</th>\n' +
                                '               <th>材料规格</th>\n' +
                                '               <th>申请人</th>\n' +
                                '               <th>申请数量</th>\n' +
                                '               <th>计量单位</th>\n' +
                                '               <th style="width: 50px;">审核量</th>\n' +
                                '               <th>材料供应商</th>\n' +
                                '               <th>审核状态</th>\n' +
                                '               <th>审核意见</th>\n' +

                                '           </thead>\n' +
                                '<tbody></tbody>' +
                                '</table>' +
                                '</div>')
                        }
                        switch (datas[i].validate) {             //判断状态
                            case -1:
                                datas[i].validate = '审核中';
                                break;
                            case 0:
                                datas[i].validate = '通过';
                                break;
                            case 1:
                                datas[i].validate = '不通过';
                                break;
                            case 2:
                                datas[i].validate = '已发货';
                                break;
                        };
                        //添加非共有部分
                        $("[names='11']").next().next().next().children().children('tbody').append(' <tr _id="'+datas[i].id+'" matType="'+datas[i].mat_Type+'">\n' +
                            '        <td>' + datas[i].mat_Name + '</td>\n' +
                            '        <td>' + datas[i].mat_Spec + '</td>\n' +
                            '        <td>' + datas[i].feed_sqr + '</td>\n' +
                            '           <td>' + datas[i].feed_Num + '</td>\n' +
                            '           <td>' + datas[i].mat_Bit + '</td>\n' +
                            '        <td class="shenheliang kedong"><input type="number" value="'+datas[i].feed_Num+'" class="layui-input"/></td>\n' +
                            '        <td class="cailiao kedong" mat_Type="mat_Type"></td>\n' +
                            '        <td class="zhuantai kedong"></td>\n' +

                            '        <td class="yijian kedong"><input type="text" class="layui-input"/></td>\n' +
                            '    </tr>')

                        $('.cailiao').eq(i).html(' <select name="modules" lay-verify="required" lay-search="">\n' +       //材料供应商下拉
                            '        <option value="">请选择</option>\n' +
                            '    </select>');
                        $('.zhuantai').eq(i).html('<select name="" id="">\n' +       //审核下拉加载
                            '        <option value="0">审核通过</option>\n' +
                            '        <option value="1 ">审核不通过</option>\n' +
                            '    </select>')
                    };
                    form.render();
                    $('.titles').remove();


                    $('.detailedfoot table tbody tr').each(function () {            //循环所有的tr
                        var datas=new Object;               //创建新对象 接受数据以便填充页面
                        //判断当前的值  去获取之前加载的数据

                            switch ($(this).attr('mattype')){
                                case '1':
                                    datas=materials1;
                                    break;
                                case '2':
                                    datas=materials2;
                                    break;
                                case '3':
                                    datas=materials3;
                                    break;
                                case '4':
                                    datas=materials4;
                                    break;
                            }
                            for(var i=0;i<datas.length;i++){
                                $(this).children('.cailiao').children('select').append('<option value="'+datas[i].compid+'">'+datas[i].compName+'</option>')
                            }
                            form.render('select');
                    });
            });
        //提交按钮监听
        $(document).on('click','.tijiao',function () {
//                    alert(222)

            var data={};        //创建一个新对象
            data.data=[];       //对象中接受一个数组
            var zhuangtai=true;

            //console.log(data)
            $('.detailedfoot table tbody tr').each(function () {            //循环所有的tr
                var _id=$(this).attr('_id');                                                    //获取id
                var _shenhe=$(this).children('.shenheliang').children('input').val();          //获取审核数量
                var _gongyingshang=$(this).children('.cailiao').children('select').val();       //获取供应商
                var _zhuantai=$(this).children('.zhuantai').children('select').val();           //获取审核状态
                var _yijian=$(this).children('.yijian').children('input').val();                //获取意见
                var _times=new Date().format("yyyy-MM-dd hh:mm:ss");                            //获取当期时间

                if(parseInt(_shenhe)<=0){
                    layer.msg('请填写审核数量')
                    zhuangtai=false;
                    return;
                }
                if(_gongyingshang==false){
                    layer.msg('请检查供货商是否选中')
                    zhuangtai=false;
                    return;
                }

                var _obj='{"createtime": null,"valtime":null,"createuser": "","valopition": "'+_yijian+'","fv_num": '+_shenhe+',"feed_code": "","feed_num": 1, "sup_code": "'+_gongyingshang+'", "mat_id": 1,"valperson": "", "id":'+_id+', "state": 0, "updatetime": null,"remarks": "", "validate":'+_zhuantai+'}';


                data.data+=_obj+',';
                //console.log(_id,_shenhe,_gongyingshang,_zhuantai,_yijian,_times)
            });


            data.data =  "[" +data.data.substr(0,data.data.lastIndexOf(","))+ "]";
            //console.log(data)
//            JSON.stringify(data.data);
//            "p":'+getCookie('yanzheng')
            //console.log(JSON.stringify(data.data));
            //移动端提交按钮监听
            var base = new Base64();
            Btnon('.tijiao');
            if(zhuangtai){
                $.ajax({
                    type:'post',
                    url:urls+'/api/matperson/matFeedVali.do',
                    contentType: "application/json; charset=utf-8",
                    processData: false,
                    data:data.data,
                    headers: {
                        'p': base.encode(getCookie('yanzheng')),
                        'danhao': sessionStorage.danhao
                    },
                    success:function (data) {
                        //console.log()
                        //console.log(data.code)

                        if(data[0].code==0){
                            layer.msg(data[0].msg);
                            setTimeout(function () {
                                location.href='./cailiaoshenqingshenpi.html';
                                Btnoff('.tijiao');
                            },1000)

                        }else{
                            layer.msg(data.msg);
                            Btnoff('.tijiao');
                        }

                    },
                    error:function (res) {
                        //console.log(res)
                        Btnoff('.tijiao')

                    }

                });
            }else{Btnoff('.tijiao')};

            return false;
        })



        //提交按钮监听
//        $(document).on('click','.tijiaos',function () {
////                    alert(222)
//            var data={};        //创建一个新对象
//            data.data=[];       //对象中接受一个数组
//            var zhuangtai=true;
//            //console.log(data)
//            $('.MOVE_table .layui-table tbody tr').each(function () {            //循环所有的tr
//                var _id=$(this).attr('id');                                                    //获取id
//                var _shenhe=$(this).children('._num ').children('input').val();          //获取审核数量
//                var _gongyingshang=$(this).children('.cailiao').children('select').val();       //获取供应商
//                var _zhuantai=$(this).children('.xuanze').children('select').val();           //获取审核状态
//                var _yijian=$(this).children('.beizu').children('input').val();                //获取意见
//                var _times=new Date().format("yyyy-MM-dd hh:mm:ss");                            //获取当期时间
//                if(_gongyingshang){
////                    layer.msg('请选择供货商');
//                    alert('我空了啊')
//                    zhuangtai=false;
//                    return;
//                }
//
//
//                var _obj='{"createtime": null,"valtime":null,"p":'+getCookie('yanzheng')+',"createuser": "","valopition": "'+_yijian+'","fv_num": '+_shenhe+',"feed_code": "","feed_num": 1, "sup_code": "'+_gongyingshang+'", "mat_id": 1,"valperson": "", "id":'+_id+', "state": 0, "updatetime": null,"remarks": "", "validate":'+_zhuantai+'}';
//
//                data.data+=_obj+',';
//                //console.log(_id)
//            });
//
//            data.data =  "[" +data.data.substr(0,data.data.lastIndexOf(","))+ "]";
//            //console.log( data)
////            JSON.stringify(data.data);
//
//            //console.log(JSON.stringify(data.data));
//            if(zhuangtai){
//                $.ajax({
//                    type:'post',
//                    url:urls+'/api/matperson/matFeedVali.do',
//                    contentType: "application/json; charset=utf-8",
//                    processData: false,
//                    data:data.data,
//                    success:function (data) {
//                        console(data)
//                        if(data.code==0){
//                            layer.msg(data.msg);
//                            setTimeout(function () {
//                                location.href='./cailiaoshenqingshenpi.html';
//                            },1000)
//
//                        }
//
//                    },
//                    error:function (res) {
//                        //console.log(res)
//                    }
//
//                });
//
//            }
//
//
//            return false;
//        })
    })
</script>
</body>
</html>